package com.ysm.smfu.activity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ysm.smfu.R;
import com.ysm.smfu.fragment.JiFenFragment;
import com.ysm.smfu.fragment.MingXiFragment;
import com.ysm.smfu.fragment.PaysetMoneyFragment;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/10/14.
 */
public class PaySetActivity extends BaseActivity {
    @BindView(R.id.title_body)
    TextView titleBody;
    @BindView(R.id.mainActivity_topbar_img)
    ImageView mainActivityTopbarImg;
    private int pay;
    private BroadcastReceiver receiver;
    private int zhangdanmingxi;

    @Override
    protected void init() {
        super.initData();
        pay = getIntent().getIntExtra("pay", -1);

        zhangdanmingxi = getIntent().getIntExtra("zhangdanmingxi", -1);


    }

    @Override
    protected void initViews() {
        super.initViews();
        setContentView(R.layout.activity_payset_container);
        ButterKnife.bind(this);

        //        查看账单
        if (zhangdanmingxi == 0) {
            titleBody.setText("收款明细");
            mainActivityTopbarImg.setVisibility(View.GONE);
            fragment = new MingXiFragment();
        }

//        关闭自身的监听
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("finish_paysetActivity");
        receiver = new MyReceiver();
        registerReceiver(receiver, intentFilter);
    }

    class MyReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            finish();
        }
    }

    Fragment fragment;

    @Override
    protected void initData() {
        super.initData();
        mainActivityTopbarImg.setVisibility(View.GONE);
        switch (pay) {
            case 0:
                // 空白二维码页
                titleBody.setText("消费订单二维码");
                fragment = new PaysetMoneyFragment();
                break;
            case 1:
                //兑换券设置页
                titleBody.setText("兑换券订单金额设置");
                fragment = new JiFenFragment();
                break;
        }
        getSupportFragmentManager().beginTransaction().replace(R.id.payset_container, fragment).commit();
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(receiver);
    }
}
